home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1272 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.iddis.com!jarnot
  2. From: jarnot@iddis.com (Kevin J. Jarnot)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Variable paramater list macros
  5. Date: 11 Jan 1996 21:54:56 GMT
  6. Organization: IDD Information Services
  7. Message-ID: <JARNOT.96Jan11165456@box10.dstar.iddis.com>
  8. References: <4crc3v$hm8@barnacle.iol.ie> <TANMOY.96Jan8085718@qcd.lanl.gov>
  9. Reply-To: jarnot@iddis.com
  10. NNTP-Posting-Host: box10.dstar.iddis.com
  11. To: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya),derekh@iol.ie
  12. In-reply-to: tanmoy@qcd.lanl.gov's message of 08 Jan 1996 15:57:18 GMT
  13.  
  14. >>>>> "Tanmoy" == Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov> writes:
  15.  
  16.     Derek> In article <4crc3v$hm8@barnacle.iol.ie> derekh@iol.ie (Derek
  17.     Derek> Hardiman) writes: 
  18.     Derek> I want to replace a variable
  19.     Derek> argument list function (which I use for debugging ) with a
  20.     Derek> macro that does nothing.
  21.     Derek>    Unfortunately I can't remember how to write a macro
  22.     Derek> that takes a variable number of paramaters ! Can you ?
  23.  
  24.     Tanmoy> The question has no answer within the C
  25.     Tanmoy> language. Individual compilers may provide a way. Please
  26.     Tanmoy> ask in a system/compiler specific group.
  27.     Tanmoy> The FAQ has a little to say about this.
  28.  
  29.  
  30. Actually, this is not 100% true.  I use the following macro for debugging
  31. all the time:
  32.  
  33. #if defined(DEBUG)
  34. #define DPRINTF(args) (dprintf args)    // Only print when DEBUG is declared
  35. #else
  36. #define DPRINTF(args)                   // O/w, the code won't even be there!
  37. #endif
  38.  
  39.  
  40. dprintf() is defined as:
  41.  
  42.         void dprintf(FILE *stream, const char *fmt, ...);
  43.  
  44.  
  45. Now, the trick is to call DPRINTF() like this:
  46.  
  47.     DPRINTF((stdout, "This is a %s param func.\n", "variable"));
  48.  
  49.  
  50. Note the double parens.  The chars within the internal parens are passed into
  51. DPRINTF as "args", and the outer remain unexpanded.  
  52.  
  53. Works like a charm.
  54.  
  55.  
  56. Kevin
  57.  
  58.  
  59.  
  60. -- 
  61. Kevin J. Jarnot - Senior Software Engineer | mailto:jarnot@iddis.com 
  62. IDD Information Services  Waltham, MA      | http://www-cs.canisius.edu/~jarnot
  63.